package com.hbt.english.controller;

import com.hbt.api.entity.CommonResult;
import com.hbt.api.entity.MulFileAndToken;
import com.hbt.api.entity.User;
import com.hbt.english.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;

@RestController
@RequestMapping("/user_provider")
public class UserProviderController {
    @Autowired
    UserService userService;
    @Value("${img_path}")
    String img_path;

    @RequestMapping("test")
    public String test(){
        return "test success";
    }

    @PostMapping("uploadAvatar")
    public CommonResult uploadAvatar(@RequestBody MultipartFile file){

        System.out.println("userprovider uploadAvatar start**********************");
        if (file!=null){
            System.out.println("file != null");
            System.out.println("文件名"+file.getOriginalFilename());
        }else{
            System.out.println("file == null");
        }
//        if (token!=null){
//            System.out.println("token != null:"+token);
//        }else{
//            System.out.println("token == null");
//        }
        System.out.println("userprovider uploadAvatar end**********************");
        return null;
    }

    @PostMapping("getUserByUsername")
    public CommonResult getUserByUsername(@RequestBody String token){

        return userService.getUserByUsername(token);
    }


    @RequestMapping(value = "dologin", method = RequestMethod.POST)
    public CommonResult dologin(@RequestBody User user) {
        //日志打印
        System.out.println("enter user provider controller dologin");
        System.out.println("user:"+user);
        return userService.dologin(user);
    }
}
